from fastapi import APIRouter
from typing import List
from apps.models import Course,Course_Copy
from apps.schemas.course import TeacherCourseResponse,TeacherCourseCreate,TeacherCourseWaitResponse
teacher = APIRouter()
@teacher.get("/tea_course/{id}",response_model=List[TeacherCourseResponse])
async def get_tea_course(id: int):
    """
    获取所有课程
    :return:
    """
    courses = await Course.filter(user_id_id = id).all()
    return courses

# 添加自己的学习课程
@teacher.post("/add_tea_course")
async def add_tea_course(body: TeacherCourseCreate):
    """
    添加自己的课程
    """
    print(body.dict())
    course = await Course.create(**body.dict())
    return {"code": 200, "msg": "添加成功", "data": course}

# 获取待处理的课程
@teacher.get("/get_wait_course/{id}",response_model=List[TeacherCourseWaitResponse])
async def get_wait_course(id : int):
    """
    获取待处理的课程
    """
    deal_course = await Course_Copy.filter(user_id_tea=id).prefetch_related("user_id_stu")
    return deal_course

@teacher.delete("/del_wait_course/{id}")
async def del_wait_course(id : int):
    """
    删除待处理的课程
    """
    await Course_Copy.filter(id=id).delete()
    return {"code": 200, "msg": "删除成功"}
